﻿// <copyright file="Section.cs" company="SharpSTS">
// Copyright (c) 2007, 2008 All Right Reserved, http://sharpsts.com/
//
// This source is subject to the Microsoft Permissive License.
// Please see the License.txt file for more information.
// All other rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// </copyright>
// <author>Microsoft/ Barry Dorrans</author>
// <date>2008-06-20</date>
// <summary>A class for reading INI files.</summary>

namespace SharpSTS.CardWriter
{
    using System;

    /// <summary>
    /// Represents a section in an INI file.
    /// </summary>
    internal sealed class Section
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Section"/> class.
        /// </summary>
        /// <param name="sectionName">Name of the section.</param>
        /// <param name="keys">The keys within a section.</param>
        public Section(string sectionName, Key[] keys)
        {
            this.Keys = keys;
            this.Name = sectionName;
        }

        /// <summary>
        /// Gets the section name.
        /// </summary>
        internal string Name
        {
            get;
            private set;
        }

        /// <summary>
        /// Gets or sets the entries in a section.
        /// </summary>
        private Key[] Keys
        {
            get;
            set;
        }

        /// <summary>
        /// Gets the <see cref="SharpSTS.CardWriter.Key"/> at the specified index.
        /// </summary>
        /// <param name="index">The index of the section name to get.</param>
        /// <value>The key name/value pair at the specified index.</value>
        public Key this[string index]
        {
            get
            {
                foreach (Key k in this.Keys)
                {
                    if (k.Name.Equals(index, StringComparison.CurrentCultureIgnoreCase))
                    {
                        return k;
                    }
                }

                return new Key("", "");
            }
        }
    }
}